﻿namespace SdCloud {
    export module Models {
        export class ModelsListViewPage {
            constructor() {
                this.initializeDeleteLinks();
            }

            private initializeDeleteLinks() {
                $("[data-action='model-delete']").click((event) => {
                    var targetButton = $(event.currentTarget);
                    event.preventDefault();
                    if (confirm("Are you sure to delete this model?")) {
                        var actionUrl = targetButton.attr("href");
                        $.ajax({
                            url: actionUrl,
                            method: "POST",
                            success: (result: Utils.IRedirectStatusModel) => {
                                if (result && result.RedirectUrl) {
                                    window.location.replace(result.RedirectUrl);
                                }
                            }
                        });
                    }
                });
            }
        }
    }
}